
*for REStat paper "Breastfeeding and Children's Early Cognitive Outcomes."

/* PSID DATA CENTER *****************************************************
   JOBID            : 126280                            
   DATA_DOMAIN      : CDS                               
   USER_WHERE       : NULL                              
   FILE_TYPE        : CDS Kids Only                     
   OUTPUT_DATA_TYPE : ASCII                             
   STATEMENTS       : SAS Statements                    
   CODEBOOK_TYPE    : HTML                              
   N_OF_VARIABLES   : 57                                
   N_OF_OBSERVATIONS: 3563                              
   MAX_REC_LENGTH   : 163                               
   DATE & TIME      : May 19, 2011 @ 11:18:43
************************************************************************/

libname dd 'X:\Donnanew';

FILENAME pch08 "X:\Donnanew\pch08.txt" ;

DATA x;
   ATTRIB
      ER30001  FORMAT=F4.   LABEL="1968 INTERVIEW NUMBER"                   
      ER30002  FORMAT=F3.   LABEL="PERSON NUMBER                         68"
      ER33401  FORMAT=F5.   LABEL="1997 INTERVIEW NUMBER"                   
      ER33402  FORMAT=F2.   LABEL="SEQUENCE NUMBER                       97"
      ER33403  FORMAT=F2.   LABEL="RELATION TO HEAD                      97"
      CHRACE   FORMAT=F1.   LABEL="CHILD RACE"                              
      AGEATCH  FORMAT=F5.1  LABEL="AGE AT CHILD INTERVIEW IN MONTHS"        
      AGEATPCG FORMAT=F5.1  LABEL="AGE AT PCG INTERVIEW IN MONTHS"          
      NEWIMMI  FORMAT=F1.   LABEL="WHETHER IN NEW IMMIGRANT SAMPLE"         
      PCG      FORMAT=F1.   LABEL="ROLE RELATION PCG"                       
      OCG      FORMAT=F1.   LABEL="ROLE RELATION OCG"                       
      RELPCG97 FORMAT=F2.   LABEL="RELATION PCG 97"                         
      RELOCG97 FORMAT=F2.   LABEL="RELATION OCG 97"                         
      CH97PRWT FORMAT=F7.3  LABEL="CHILD LEVEL WEIGHT"                      
      PCGHHBWT FORMAT=F7.3  LABEL="PCG - HOUSEHOLD BOOKLET WEIGHT"          
      Q1A1     FORMAT=F1.   LABEL="ASSESSMENT 97"                           
      Q1PCRAW  FORMAT=F2.   LABEL="PC RAW SCORE 97"                         
      Q1A6     FORMAT=F1.   LABEL="RACIAL DESCRIPTION 97"                   
      Q1A7A    FORMAT=F4.1  LABEL="DAYS AFTER DUE DATE 97"                  
      Q1A7B    FORMAT=F3.   LABEL="DAYS BEFORE DUE DATE 97"                 
      Q1A8P    FORMAT=F2.   LABEL="BIRTH WEIGHT (POUNDS) 97"                
      Q1A8O    FORMAT=F5.2  LABEL="BIRTH WEIGHT (OUNCES) 97"                
      Q1A10    FORMAT=F1.   LABEL="BRFEED AS INFANT 97"                     
      Q1A10A   FORMAT=F5.2  LABEL="AGE STOPPED BRFEED 97"                   
      Q1A15    FORMAT=F1.   LABEL="WIC PROGRAM-PREGNANT 97"                 
      Q1J1     FORMAT=F1.   LABEL="RESIDENCE OF PARENTS 97"                 
      Q1J19    FORMAT=F1.   LABEL="MARITAL STATUS-MOTHER 97"                
      HOME1    FORMAT=F4.1  LABEL="FULL HOME SCALE 97"                      
      POSBEH97 FORMAT=F4.2  LABEL="POSITIVE BEHAVIOR SCALE 97"              
      WARMTH97 FORMAT=F4.2  LABEL="PARENTAL WARMTH SCALE 97"                
      Q3AGE    FORMAT=F2.   LABEL="AGE OF CHILD 97"                         
      Q3LW_SS  FORMAT=F3.   LABEL="LW STND SCORE 97"                        
      Q3PC_SS  FORMAT=F3.   LABEL="PC STND SCORE 97"                        
      Q3CAL_SS FORMAT=F3.   LABEL="CAL STND SCORE 97"                       
      Q3AP_SS  FORMAT=F3.   LABEL="APPLIED PROB STND SCORE 97"              
      Q3BMA_SS FORMAT=F3.   LABEL="BROAD MATH SCORE 97"                     
      ER33601  FORMAT=F4.   LABEL="2001 INTERVIEW NUMBER"                   
      ER33602  FORMAT=F2.   LABEL="SEQUENCE NUMBER                       01"
      ER33603  FORMAT=F2.   LABEL="RELATION TO HEAD                      01"
      RELPCG02 FORMAT=F2.   LABEL="RELATION PCG 02"                         
      RELOCG02 FORMAT=F2.   LABEL="RELATION OCG 02"                         
      CH02PRWT FORMAT=F6.3  LABEL="CHILD LEVEL WEIGHT 02"                   
      PCGRES02 FORMAT=F1.   LABEL="PCG CH IW RESULT 02"                     
      OCGRES02 FORMAT=F1.   LABEL="OCG IW RESULT 02"                        
      Q21A2    FORMAT=F1.   LABEL="BRFEED AS INFANT 02"                     
      Q21A2A   FORMAT=F2.   LABEL="AGE STOPPED BRFEED 02"                   
      Q21IWAGE FORMAT=F5.2  LABEL="CHILD AGE AT TIME OF PCG IW - YEARS 02"  
      POSBEH02 FORMAT=F4.2  LABEL="POSITIVE BEHAVIOR SCALE 02"              
      WARMTH02 FORMAT=F4.2  LABEL="PARENTAL WARMTH SCALE 02"                
      HT1_02   FORMAT=F3.1  LABEL="HOME Total 3-5 Yrs 02"                   
      HT2_02   FORMAT=F3.1  LABEL="HOME Total 6-9 Yrs 02"                   
      CDI_02   FORMAT=F2.   LABEL="CDI Short Form 02"                       
      Q24LWSS  FORMAT=F3.   LABEL="LW STD SCORE 02"                         
      Q24PCSS  FORMAT=F3.   LABEL="PC STND SCORE 02"                        
      Q24BRSS  FORMAT=F3.   LABEL="BROAD READING SCORE 02"                  
      Q24APSS  FORMAT=F3.   LABEL="APPLIED PROB STD SCORE 02"               
      Q24IWAGE FORMAT=F3.   LABEL="CHILD AGE AT ASSESSMENT - MONTHS 02"     
   ;
   INFILE pch08 LRECL = 163 ; 
   INPUT 
      ER30001      1 - 4     ER30002      5 - 7     ER33401      8 - 12   
      ER33402     13 - 14    ER33403     15 - 16    CHRACE      17 - 17   
      AGEATCH     18 - 22    AGEATPCG    23 - 27    NEWIMMI     28 - 28   
      PCG         29 - 29    OCG         30 - 30    RELPCG97    31 - 32   
      RELOCG97    33 - 34    CH97PRWT    35 - 41    PCGHHBWT    42 - 48   
      Q1A1        49 - 49    Q1PCRAW     50 - 51    Q1A6        52 - 52   
      Q1A7A       53 - 56    Q1A7B       57 - 59    Q1A8P       60 - 61   
      Q1A8O       62 - 66    Q1A10       67 - 67    Q1A10A      68 - 72   
      Q1A15       73 - 73    Q1J1        74 - 74    Q1J19       75 - 75   
      HOME1       76 - 79    POSBEH97    80 - 83    WARMTH97    84 - 87   
      Q3AGE       88 - 89    Q3LW_SS     90 - 92    Q3PC_SS     93 - 95   
      Q3CAL_SS    96 - 98    Q3AP_SS     99 - 101   Q3BMA_SS   102 - 104  
      ER33601    105 - 108   ER33602    109 - 110   ER33603    111 - 112  
      RELPCG02   113 - 114   RELOCG02   115 - 116   CH02PRWT   117 - 122  
      PCGRES02   123 - 123   OCGRES02   124 - 124   Q21A2      125 - 125  
      Q21A2A     126 - 127   Q21IWAGE   128 - 132   POSBEH02   133 - 136  
      WARMTH02   137 - 140   HT1_02     141 - 143   HT2_02     144 - 146  
      CDI_02     147 - 148   Q24LWSS    149 - 151   Q24PCSS    152 - 154  
      Q24BRSS    155 - 157   Q24APSS    158 - 160   Q24IWAGE   161 - 163  

   ;

data y;
set x;

*first, form child unique id;
childid = .;
childid = er30001*1000 + er30002;

**I want this info. from bio. mom only, so let's identify pcg;
**relpcg97 = 1 means biological mother;
if relpcg97 = 1 then do;

*mom's score on pc test;
mompcraw = .;
if (q1pcraw ge 4 and q1pcraw le 43) then mompcraw = q1pcraw;

*home score;
home97 = .;
if home1 gt 0 then home97 = home1;

*parental warmth scale;
warm97 = .;
if (warmth97 gt 0 and warmth97 lt 6) then warm97 = warmth97;

*parental positive behaviors scale;
pos97 = .;
if (posbeh97 gt 0 and posbeh97 lt 6) then pos97 = posbeh97;

*birthweight le 5.5 pounds;
le55lb = .;
if (q1a8p gt 5 and q1a8p le 15) then le55lb = 0;
if (q1a8p ge 1 and q1a8p le 4) then le55lb = 1;
if q1a8p = 5 then do;
   if (q1a8o ge 0 and q1a8o le 8) then le55lb = 1;
   if q1a8o = 96 then le55lb = 1;
   if (q1a8o gt 8 and q1a8o lt 16) then le55lb = 0;
end;

*forgot to pull off one variable, see everything merged in below;
*will care if low;
*gestwk = .;
**whoops, merge in later;
**if q1a7 = 3 then gestwk = 40;
*if (q1a7a gt 0 and q1a7a lt 60) then gestwk = 40;
*if (q1a7b ge 1 and q1a7b le 170) then do;
*gestwk = 40 - q1a7b/7;
*end;

*WIC while pregnant;
wic97 = .;
if q1a15 = 1 then wic97 = 1;
if q1a15 = 5 then wic97 = 0;

*breastfeeding information;
bfeed = .;
if q1a10 = 1 then bfeed = 1;
if q1a10 = 5 then bfeed = 0;
bfmo = .;
if bfeed = 1 then do;
   if (q1a10a ge 1 and q1a10a le 60) then bfmo = q1a10a;
   if q1a10a = 96 then bfmo = .5;
end;
*fill in with 2002 info...if pcg is bio mom;
if relpcg02 = 1 then do;
if (q21a2 = 1 and bfmo = . and bfeed = 1) then do;
    if (q21a2a ge 1 and q21a2a le 50) then bfmo = q21a2a;
end;
**four people switched over to yes, with months info..., will change;
if (q21a2 = 1 and bfmo = . and bfeed = 0) then do;
    bfeed = 1;
    if (q21a2a ge 1 and q21a2a le 50) then bfmo = q21a2a;
end;
end;
end;

*will use parent scales for 1997, since 2001 has different home scale;

**new immigrant sample;
if newimmi = 5 then newimmi = 0;
if newimmi = 1 then newimmi = 1;

*age at assessment, second one in months;
age97 = .;
if (AGEATCH ge 16 and AGEATCH le 164) then age97 = AGEATCH;
age97 = age97/12;

age02 = .;
if (q24iwage ge 63 and q24iwage le 232) then age02 = q24iwage;
age02 = age02/12;

**W-C test scores, note younger kids only get lw and ap;  
lw97= .;
if (q3lw_ss ge 42 and q3lw_ss le 197) then lw97 = q3lw_ss;

ap97 = .;
if (q3ap_ss ge 28 and q3ap_ss le 159) then ap97 = q3ap_ss;

**now, 2002;
lw02= .;
if (q24lwss ge 20 and q24lwss le 200) then lw02 = q24lwss;

ap02 = .;
if (q24apss ge 15 and q24apss le 200) then ap02 = q24apss;

**child race;
chblack = .;
if (chrace = 2) then chblack = 1;
if (chrace = 1 or chrace = 3 or chrace = 4 or chrace = 5 or chrace = 7) then chblack = 0;
chhisp = .;
if (chrace = 3) then chhisp = 1;
if (chrace = 1 or chrace = 2 or chrace = 4 or chrace = 5 or chrace = 7) then chhisp = 0;

proc sort;  by childid;  run;

******;
**now, I want to look at the individual file to get some basic variables about the child;
data z;
set dd.pind08;
keep childid momid dadid border marbirth femch childmob childyob;

childid = .;
childid = er30001*1000 + er30002;

momid = er32009*1000 + er32010;

dadid = er32016*1000 + er32017;

*birth order;
border = .;
if (er32013 gt 0 and er32013 le 30) then border = er32013;

*marbirth = .;
*I'm going to count separated as still married, to be consistent with NLSY79;
if (er32015 = 1 or er32015 = 5) then marbirth = 1;
else if (er32015 ge 2 and er32015 le 7) then marbirth = 0;

*gender;
femch = .;
if er32000 = 1 then femch = 0;
if er32000 = 2 then femch = 1;

*birthdate;
childmob = .;
if (er33405 ge 1 and er33405 le 12) then childmob = er33405;
childyob = .;
if (er33406 ge 1000 and er33406 le 2000) then childyob = er33406;


proc sort;  by childid;


data z2;
merge y z;  by childid;
if chrace ne .;

proc sort;  by childid;  run;

data z3;
set dd.pgest08;

proc sort;  by childid;  run;


data z4;
merge z2 z3;  by childid;

*will care if low;
gestwk = .;
if q1a7 = 3 then gestwk = 40;
if (q1a7a gt 0 and q1a7a lt 60) then gestwk = 40;
if (q1a7b ge 1 and q1a7b le 170) then do;
gestwk = 40 - q1a7b/7;
end;

proc sort;  by childid; 

*so can compare to parent ids in mapids SAS program;
****data dd.momdadid;
****set z4;
****keep childid momid dadid childmob childyob relpcg97;

**now merge in bio mom's hgc and month and year of birth;
data z5;
set dd.momed08;
proc sort;  by childid;

data z6;
merge z4 z5; by childid;

proc sort;  by childid;

**now merge in bio father's education;
data z7;
set dd.daded08;

proc sort;  by childid;  

data z8;
merge z6 z7;  by childid;

proc sort;  by childid;

**now merge in from family file, region of interview, year of child's birth and pcg 
**race/ethnicity;

data z9;
set dd.pfam083;
proc sort;  by childid;

data z10;
merge z8 z9;  by childid;

proc sort;  by childid;

**now add in mother's religion;
data z11;
set dd.relmom2;
proc sort;  by childid;


**this is all of the merged data;
data dd.pch08;
merge z10 z11;  by childid;

proc means;
run;

